package cn.itcast.bos.web.action.base;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;

import cn.itcast.bos.domain.base.Standard;
import cn.itcast.bos.service.base.StandardService;
import cn.itcast.bos.web.action.common.BaseAction;

import com.opensymphony.xwork2.ActionContext;

/**
 * bos物流的物品的标准，standard
 * 
 * @author Administrator
 *
 */
@Controller
@ParentPackage("json-default")
@Namespace("/")
@Scope("prototype")
public class StandardAction extends BaseAction<Standard> {
	// 用到struts2不要web.xml过滤器
	@Autowired
	private StandardService standardService;

	// 取派标准的添加
	@Action(value = "standard_save", results = { @Result(name = "success", location = "./pages/base/standard.html", type = "redirect") })
	public String save() {
		standardService.save(model);
		return SUCCESS;
	}

	// 取派标准的 分页查询
	@Action(value = "standard_pageQuery", results = { @Result(name = "success", type = "json") })
	public String standardPageQuery() {

		/*if (standard.getId()!=null) {
			standardService.delete(standard);
		}*/
		Pageable pageable = new PageRequest(page - 1, rows);

		Page<Standard> pageData = standardService.findPageData(pageable);

		pushPageDataToValueStack(pageData);
		return SUCCESS;
	}

	//收派标准的不分页查询
	@Action(value="standard_fandAll",results={@Result(name="success",type="json")})
	public String fandAll() {
		List<Standard> standards=standardService.findAll();
		
		//封装json
		ActionContext.getContext().getValueStack().push(standards);
		return SUCCESS;
	}
	


	//收派标准的删除
	@Action(value="standard_delete",results={@Result(name="success",location="./pages/base/standard.html",type="redirect")})
	public String delete() {
		
		standardService.delete(tag,ids);
		return SUCCESS;
	}
}
